package com.shenmazong.servermsgapi.config;

import com.shenmazong.utils.ConstUtils;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicRabbitConfig {

    @Bean
    public Queue messageQueue() {
        return new Queue(ConstUtils.MQ_QUEUE_TOPIC_MSG_NANE);
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange(ConstUtils.MQ_EXCHANGE_TOPIC_MSG_NAME);
    }


    //将firstQueue和topicExchange绑定,而且绑定的键值为topic.man
    //这样只要是消息携带的路由键是topic.man,才会分发到该队列
    @Bean
    Binding bindingExchangeMessage() {
        return BindingBuilder.bind(messageQueue()).to(exchange()).with(ConstUtils.MQ_QUEUE_TOPIC_MSG_NANE);
    }
}
